clear all;

P = [
      1 0 0 0 1 1 1 0 1 1 0 1;
      0 0 0 1 1 1 0 1 1 0 1 1;
      0 0 1 1 1 0 1 1 0 1 0 1;
      0 1 1 1 0 1 1 0 1 0 0 1;
      1 1 1 0 1 1 0 1 0 0 0 1;
      1 1 0 1 1 0 1 0 0 0 1 1;
      1 0 1 1 0 1 0 0 0 1 1 1;
      0 1 1 0 1 0 0 0 1 1 1 1;
      1 1 0 1 0 0 0 1 1 1 0 1;
      1 0 1 0 0 0 1 1 1 0 1 1;
      0 1 0 0 0 1 1 1 0 1 1 1;
      1 1 1 1 1 1 1 1 1 1 1 0
    ];

G = [P eye(12)];

[k, n] = size(G);


% Geracao das Palavras Codigo
palavrasCod = zeros(1,k) * G;
for count_dec = 0:(2^k - 1)
    
    % Rotina para transformar um decimal num vetor binario
    % Inicia-se com um vator vazio,
    count_bin = [];
    while count_dec > 1
        count_bin = [mod(count_dec,2) count_bin]; % concatenando cada digito binario
        count_dec = floor(count_dec/2);   % atualizando o quociente.
    end
    count_bin = [count_dec count_bin];    % Concatenando o ultimo quociente

    % Preenche count_bin com zeros a esquerda
    [r,c] = size(count_bin);
    count_bin = [zeros(1,k-c),count_bin];
    
    pc_aux = count_bin * G;
    %Formata em Modulo-2
    pc_aux = abs(mod(round(pc_aux),2));
    
    % Verifica os elementos ja calculados
    isNewElem = 1;
    [r,c] = size(palavrasCod);
    for i = 1:r
        pc_elem(1,:) = palavrasCod(i,:);
    
        if (pc_elem == pc_aux)
            isNewElem = 0;
            break;
        end
    end
    
    if (isNewElem == 1)
        palavrasCod = [palavrasCod; pc_aux];
    end
end

select_list = [
                1 2 3 4 5 6 7 8 9 10 11 12;
                1 2 3 4 5 6 7 8 9 10 11 13;
                1 2 3 4 5 6 7 8 9 10 11 14;
                1 2 3 4 5 6 7 8 9 10 12 13;
                1 2 3 4 5 6 7 8 9 10 12 14;
                1 2 3 4 5 6 7 8 9 11 12 13;
                1 2 3 4 5 6 7 8 9 10 11 15;
                1 2 3 4 5 6 7 8 9 11 12 14;
                1 2 3 4 5 6 7 8 9 10 12 15;
                1 2 3 4 5 6 7 8 9 10 13 14;
                1 2 3 4 5 6 7 8 10 11 12 13;
                1 2 3 4 5 6 7 8 9 10 11 16;
                1 2 3 4 5 6 7 8 9 11 12 15;
                1 2 3 4 5 6 7 8 9 10 13 15;
                1 2 3 4 5 6 7 8 9 11 13 14;
                1 2 3 4 5 6 7 8 9 10 12 16;
                1 2 3 4 5 6 7 8 10 11 12 14;
                1 2 3 4 5 6 7 9 10 11 12 13;
                1 2 3 4 5 6 7 8 9 11 13 15;
                1 2 3 4 5 6 7 8 9 10 11 17;
                1 2 3 4 5 6 7 8 9 11 12 16;
                1 2 3 4 5 6 7 8 10 11 12 15;
                1 2 3 4 5 6 7 8 10 11 13 14;
                1 2 3 4 5 6 7 8 9 10 13 16;
                1 2 3 4 5 6 7 9 10 11 12 14;
                1 2 3 4 5 6 7 8 9 10 12 17;
                1 2 3 4 5 6 7 8 9 11 13 16;
                1 2 3 4 5 6 7 8 10 11 13 15;
                1 2 3 4 5 6 7 8 10 11 12 16;
                1 2 3 4 5 6 7 8 9 11 12 17;
                1 2 3 4 5 6 7 8 9 10 13 17;
                1 2 3 4 5 6 7 9 10 11 13 14;
                1 2 3 4 5 6 7 9 10 11 12 15;
                1 2 3 4 5 6 7 8 10 11 13 16;
                1 2 3 4 5 6 7 8 9 11 13 17;
                1 2 3 4 5 6 7 8 10 11 12 17;
                1 2 3 4 5 6 7 9 10 11 13 15;
                1 2 3 4 5 6 7 9 10 11 12 16;
                1 2 3 4 5 6 7 9 10 11 13 17;
                1 2 3 4 5 6 7 9 10 11 12 17;
                1 2 3 4 5 6 7 9 10 11 13 16
            ];
        
save env24_12.mat G n k palavrasCod select_list